package com.lyf.spring.demo.controller;

import com.lyf.spring.demo.model.UserInfo;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/resp")
//@RestController（返回数据）=@ResponseBody+@Controller
@Controller//返回页面

public class RespController {
    @RequestMapping("r1")
    public String returnPage(){
        return "/aa/index.html";//要加/不然显示不出页面
    }

    @ResponseBody
    @RequestMapping("r2")
    public String returnData(){
        return "返回数据";
    }

    @ResponseBody
    @RequestMapping("r3")
    public String returnHTML(){
        return "<h1>qwe</h1>";
    }

    //produces就是content-type文本类型
    @ResponseBody
    @RequestMapping(value = "r4",produces = "text/html")
    public String returnText(){
        return "<h2>wqewqe</h2>";
    }

    @ResponseBody
    @RequestMapping(value = "r5")
    public UserInfo returnJson(){
        UserInfo userInfo=new UserInfo("zhangsan",1,1);
        return  userInfo;
    }

    @ResponseBody
    @RequestMapping(value = "r6")
    public  UserInfo setState(HttpServletResponse respone){
        respone.setStatus(404);
        UserInfo userInfo=new UserInfo("zhangsan",1,1);
        return userInfo;
    }

    @ResponseBody
    @RequestMapping(value = "r7")
    public  String setHeader(HttpServletResponse response){
        response.setHeader("myHeader","myHeader");
        return "设置Header成功";
    }
}
